import type { EnumApi } from '#/api/';

import { requestClient } from '#/api/request';

export namespace SubjectApi {
  export type Params = object;
  // 定义字典枚举[{label: '设备点检', value: 'CHECK'}]

  export interface GetSubjectReq {
    pageNum: number;
    pageSize: number;
    planId?: number;
    subjectType?: EnumApi.DvPlanTypeEnum;
  }
  export interface Row {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    subjectId: number;
    subjectCode: string;
    subjectName: string;
    subjectType: string;
    subjectContent: string;
    subjectStandard: null | string;
    enableFlag: string;
    attr1: null | string;
    attr2: null;
    attr3: number;
    attr4: number;
  }
  export interface GetSubjectListResp {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }

  export interface CheckRow {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: null;
    remark: string;
    params: Params;
    recordId: number;
    planId: number;
    subjectId: number;
    subjectCode: string;
    subjectName: string;
    subjectType: EnumApi.DvPlanTypeEnum;
    subjectContent: string;
    subjectStandard: null;
    attr1: null | string;
    attr2: null;
    attr3: number;
    attr4: number;
  }

  export interface GetCheckSubjectListResp {
    total: number;
    rows: CheckRow[];
    code: number;
    msg: string;
  }
}

// 获取类型列表
export const getSubjectList = (params: SubjectApi.GetSubjectReq) =>
  requestClient.get<SubjectApi.GetSubjectListResp>('/mes/dv/dvsubject/list', {
    params,
  });

// 修改保养项目设置
export const updateSubject = (data: SubjectApi.Row) =>
  requestClient.put<SubjectApi.GetSubjectListResp>('/mes/dv/dvsubject', data);

// 增加保养项目设置
export const addSubject = (data: SubjectApi.Row) =>
  requestClient.post<SubjectApi.GetSubjectListResp>('/mes/dv/dvsubject', data);

// 删除保养项目设置
export const deleteSubject = (id: string) =>
  requestClient.delete<SubjectApi.GetSubjectListResp>(
    `/mes/dv/dvsubject/${id}`,
  );

// 获取Tabs 保养项目设置列表
export const getCheckSubjectList = (params: SubjectApi.GetSubjectReq) =>
  requestClient.get<SubjectApi.GetCheckSubjectListResp>(
    '/mes/dv/checksubject/list',
    {
      params,
    },
  );

// 修改Tabs 保养项目设置
export const updateCheckSubject = (data: SubjectApi.CheckRow) =>
  requestClient.put<SubjectApi.GetCheckSubjectListResp>(
    '/mes/dv/checksubject',
    data,
  );

// 增加Tabs 保养项目设置
export const addCheckSubject = (data: SubjectApi.CheckRow) =>
  requestClient.post<SubjectApi.GetCheckSubjectListResp>(
    '/mes/dv/checksubject',
    data,
  );

// 删除Tabs 保养项目设置
export const deleteCheckSubject = (id: string) =>
  requestClient.delete<SubjectApi.GetCheckSubjectListResp>(
    `/mes/dv/checksubject/${id}`,
  );
